package com.zw.controller;

import com.github.pagehelper.PageInfo;
import com.zw.dto.AddBasicDataDto;
import com.zw.dto.ApplyRecordPagesDto;
import com.zw.dto.PermApplyDto;
import com.zw.dto.PermAuditDto;
import com.zw.entity.PermissionApplyRecord;
import com.zw.service.PermissionApplyRecordService;
import com.zw.vo.ApplyRecordPagesVO;
import com.zw.vo.ResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * (PermissionApplyRecord)表控制层
 *
 * @author makejava
 * @since 2025-03-25 23:41:46
 */
@RestController
@RequestMapping("permissionApplyRecord")
@Api(value = "权限操作API", tags = "权限操作API")
public class PermissionApplyRecordController {
    /**
     * 服务对象
     */
    @Resource
    private PermissionApplyRecordService permissionApplyRecordService;

    /**
     * 权限申请
     *
     * @param dto 上传数据请求dto
     * @return 结果
     */
    @ApiOperation("权限申请")
    @PostMapping("/permApply")
    public ResponseVO permApply(@RequestBody @Valid PermApplyDto dto) {
        try {
            Boolean permApply = permissionApplyRecordService.permApply(dto);
            return new ResponseVO(permApply);
        } catch (Exception e) {
            e.printStackTrace();
            if (e instanceof RuntimeException){
                throw new RuntimeException(e.getMessage());
            }
            throw new RuntimeException("权限申请失败，请联系管理员处理！");
        }
    }

    /**
     * 权限审核列表分页查询
     *
     * @param dto 上传数据请求dto
     * @return 结果
     */
    @ApiOperation("权限审核列表分页查询")
    @PostMapping("/applyRecordPages")
    public ResponseVO<ApplyRecordPagesVO> applyRecordPages(@RequestBody @Valid ApplyRecordPagesDto dto) {
        try {
            PageInfo<ApplyRecordPagesVO> permApply = permissionApplyRecordService.applyRecordPages(dto);
            return new ResponseVO(permApply);
        } catch (Exception e) {
            e.printStackTrace();
            if (e instanceof RuntimeException){
                throw new RuntimeException(e.getMessage());
            }
            throw new RuntimeException("权限审核列表分页查询失败，请联系管理员处理！");
        }
    }
    /**
     * 权限审核
     *
     * @param dto 上传数据请求dto
     * @return 结果
     */
    @ApiOperation("权限审核")
    @PostMapping("/permAudit")
    public ResponseVO<Boolean> permAudit(@RequestBody @Valid PermAuditDto dto) {
        try {
            Boolean permAudit = permissionApplyRecordService.permAudit(dto);
            return new ResponseVO(permAudit);
        } catch (Exception e) {
            e.printStackTrace();
            if (e instanceof RuntimeException){
                throw new RuntimeException(e.getMessage());
            }
            throw new RuntimeException("权限审核失败，请联系管理员处理！");
        }
    }
}

